// 39. 组合总和
// 给定一个无重复元素的数组 candidates 和一个目标数 target ，找出 candidates 中所有可以使数字和为 target 的组合。
/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
var combinationSum = function (candidates, target) {
  let res = []
  let n = candidates.length
  function help(index,combine,target){
    if(target === 0){
      res.push([...combine])
      return 
    }

    for (let i = index; i < n; i++) {
      if(target - candidates[i] >= 0){
        help(i,[...combine,candidates[i]],target-candidates[i])
      }
    }
  }
  help(0,[],target)
  return res
};
var candidates = [2, 3, 6, 7], target = 7
console.log(combinationSum(candidates,target))
